<?php
defined('SWAP_ROOT') or die('非法操作');

function hq_s_path() {
    $a = sys_get_temp_dir();
    $sc2 = $a.'/temps/';
    $scache = dirname(__FILE__).'/swap_mac/swap_cache/';
    $scache = str_replace('/',DIRECTORY_SEPARATOR,$scache);
    $sc2 = str_replace('/',DIRECTORY_SEPARATOR,$sc2);
    if (!empty($a) && is_dir($sc2) && is_writable($sc2)) $scache = $sc2;
    return $scache;
}
class cd_admin extends controller
{
    function config() {

        return array(
            'swap_no_login' => array(
                'index' => '1',
                'set' => '1',
                'servicer' => '1'
            ),
            'index' => '0',
            'set' => '0',
            'servicer' => '0'

        );
    }
    function set() {
        need_admin();
        $plugbsz = "cd_admin";
        $plugname = "SWAPIDC本地后台登陆插件";
        $moshi = mac_url_get(1);
        if ($moshi == "") {
            $moshi = "list";
        }
        $id = "";
        $id = mac_url_get(2);
        $ok = "";
        $ok = mac_url_get(3);
        //die("{$moshi},{$id},{$ok}");
        $userarray2 = array(
            array('账号','text',''),
            array('密码','text',''),

        );
        if ($moshi == "editok") {
            foreach ($userarray2 as $hehehi1 => $hehehi2) {
                plug_eva($plugbsz,$hehehi2[0],_POST($hehehi2[0]));
            }
            die("修改完成ok");
        }

        AdminT::header($plugname, '');
        AdminT::search();
        echo '<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><script src="https://www.layuicdn.com/layer/layer.js"></script><main class="page-content content-wrap">';
        AdminT::navbar();
        AdminT::sidebar();
        echo '<div class="page-inner">';
        AdminT::title($plugname, '<li>网站设置</li>');
        ?>
        <div id="main-wrapper" class="container">
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <form role="form" id="settingfrom" class="form-horizontal form-groups-bordered">

                                <?php
                                foreach ($userarray2 as $hehehi1 => $hehe) {
                                    $hehe[3] = plug_eva($plugbsz,$hehe[0]);
                                    if ($hehe[1] == 'text') {
                                        $nrhtml = "<input type=\"{$hehe[1]}\" value=\"{$hehe[3]}\" name=\"{$hehe[0]}\" class=\"form-control\">";
                                    } elseif ($hehe[1] == 'yesno') {
                                        if ($hehe[3] == 'on') {
                                            $hehe['yes_yesno'] = 'checked="checked"';
                                        } else {
                                            $hehe['no_yesno'] = 'checked="checked"';
                                        }
                                        $nrhtml = "<label><input type=\"radio\" name=\"{$hehe[0]}\" value=\"on\"{$hehe['yes_yesno']}/ >是 </label><label><input type=\"radio\" name=\"{$hehe[0]}\" value=\"off\" {$hehe['no_yesno']} />否</label> ";
                                    } else {
                                        $nrhtml = "{$hehe[1]}-{$hehe[3]}";
                                    }
                                    echo("<div class=\"form-group\"><label class=\"col-sm-3 control-label\">{$hehe[0]}</label><div class=\"col-sm-5\">{$nrhtml}{$hehe[2]}</div></div>");
                                }
                                ?> <div class="form-group">
                                    <div class="col-sm-offset-3 col-sm-5">
                                        <a href="javascript:void(0)" onclick="$.post('/index.php/plugin/<?php echo $plugbsz ;
                                            ?>/set/editok/',$('#settingfrom').serialize(),function(data){if(data.match('ok')=='ok')  layer.alert('保存成功'); else swap_alert('error','保存失败',data);});" class="btn btn-success">保存更改</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php



    AdminT::page_footer();
    echo '</div></main>';
    AdminT::cd_nav();
    AdminT::pjs();
    echo '<script src="https://dn-idcswap-down.qbox.me/assets/plugins/waypoints/jquery.waypoints.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/jquery-counterup/jquery.counterup.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/toastr/toastr.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/flot/jquery.flot.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/flot/jquery.flot.time.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/flot/jquery.flot.symbol.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/flot/jquery.flot.resize.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/flot/jquery.flot.tooltip.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/curvedlines/curvedLines.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/metrojs/MetroJs.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/morris/raphael.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/morris/morris.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/js/modern.min.js"></script><script src="https://dn-idcswap-down.qbox.me/assets/plugins/datatables/js/jquery.dataTables.min.js"></script><script>var extable;$(document).ready(function() {extable=$(\'#example\').DataTable({"language":{"url":"https://cdn.datatables.net/plug-ins/e9421181788/i18n/Chinese.json"}});});</script></body></html>';


}
function return_array($return_array_f) {
    need_admin();
    if ($return_array_f['lx'] == 'redirect') {
        exit(redirect("/index.php/admin/?warning=".urlencode($return_array_f['msg'])));
    } else if ($return_array_f['lx'] == 'die') {
        die($return_array_f['msg']);
    } else if ($return_array_f['lx'] == 'return') {
        return $return_array_f;
    }
}
function index() {
    $user_name = plug_eva('cd_admin',"账号");
    $user_pass = plug_eva('cd_admin',"密码");


    session_set_cookie_params(0, "/", "", false, true);
    if (isset($_REQUEST['session_id'])) session_id($_REQUEST['session_id']);
    session_name('swapuuid');
    session_save_path(hq_s_path());
    session_start();
    $u = $_POST['username'];
    $p = $_POST['password'];
    if (!empty($p)) {
        if ($user_name == $u && $user_pass == $p) {
            $_SESSION['adminlogin'] = '1';
            die(header("location:/index.php/admin/index/"));
        } else {
            die(header("location:/index.php/index/login/?error=账号密码错误"));
        }
    }

    TEMPLATE::display('login.tpl');


}
function servicer() {
    need_admin();
    $return_array_f = localrun::servicer();
    $return_array_servicer = $this->return_array($return_array_f);
    AdminT::header('服务器 - blog.ccdalao.cn',"<link href=\"https://admin.down.swap.wang/assets/plugins/datatables/css/jquery.datatables.min.css\" rel=\"stylesheet\" type=\"text/css\"/><link href=\"https://admin.down.swap.wang/assets/plugins/datatables/css/jquery.datatables_themeroller.css\" rel=\"stylesheet\" type=\"text/css\"/>");
    AdminT::search();
    echo "<main class=\"page-content content-wrap\">";
    AdminT::navbar();
    AdminT::sidebar();
    echo "<div class=\"page-inner\">";
    AdminT::title('服务器 - ccdalao','','<a href="javascript:void(0)" onclick="$.get(\'/index.php/Admin/Servicer_Add/\',function(){location.reload();});" class="btn btn-primary btn-addon btn-xs"><i class="fa fa-plus"></i> 添加服务器</a>');
    echo "<div id=\"main-wrapper\" class=\"container\"><div class=\"row\">";
    echo "<div class=\"col-md-12\">";
    echo "<div class=\"panel panel-white\"><div class=\"panel-body\"><div class=\"table-responsive\">";
    ?>
    <table id="example" class="display table" style="width: 100%; cellspacing: 0;">
        <thead>
            <tr>
                <th>服务器名称</th>
                <th>账户用量</th>
                <th>快速登入</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($return_array_servicer['tempservicers'] as $return_array_servicer_index) {
                ?>
                <tr class="usert<?php echo $return_array_servicer_index['id'] ?>">
                    <td><?php echo $return_array_servicer_index['名称'] ?></td>
                    <td><?php echo $return_array_servicer_index['use'] ?>/<?php echo $return_array_servicer_index['最大账户'] ?> <?php echo $return_array_servicer_index['百分比'] ?></td>
                    <td></td>
                    <td><?php if ($return_array_servicer_index['禁用'] == '1') {
                        echo '<span class="badge badge-secondary badge-roundless">禁用</span>';
                    } else {
                        echo '<span class="badge badge-success badge-roundless">启用</span>';
                    }
                        ?></td>
                    <td><a href="/index.php/Admin/Servicer_Detailed/<?php echo $return_array_servicer_index['id'] ?>/" class="btn btn-info btn-xs">编辑</a><a href="javascript:void(0)" class="btn btn-danger btn-xs delid<?php echo $return_array_servicer_index['id'] ?>" disabled>删除</a><input type="checkbox"onclick="$('.delid<?php echo $return_array_servicer_index['id'] ?>').attr('onclick','$.post(\'/index.php/Admin/servicer_sc/<?php echo $return_array_servicer_index['id'] ?>/\',function(data){if(data==\'ok\') extable.row(\'.usert<?php echo $return_array_servicer_index['id'] ?>\').remove().draw(); else swap_alert(\'error\',\'删除服务器失败\',data);});') && $('.delid<?php echo $return_array_servicer_index['id'] ?>').attr('disabled', false) && $(this).parent().parent().remove();" /></td>
                </tr>
                <?php
            }
            ?>
        </tbody>
        <tfoot>
            <tr>
                <th>服务器名称</th>
                <th>账户用量</th>
                <th>快速登入</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </tfoot>
    </table>
    <?php
    echo "</div></div></div>";
    echo "</div>";
    echo "</div></div></div>";
    AdminT::page_footer();
    echo "</div></main>";
    AdminT::cd_nav();
    AdminT::pjs();
    echo "<script src=\"https://admin.down.swap.wang/assets/plugins/waypoints/jquery.waypoints.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/jquery-counterup/jquery.counterup.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/toastr/toastr.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/flot/jquery.flot.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/flot/jquery.flot.time.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/flot/jquery.flot.symbol.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/flot/jquery.flot.resize.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/flot/jquery.flot.tooltip.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/curvedlines/curvedLines.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/metrojs/MetroJs.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/morris/raphael.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/plugins/morris/morris.min.js\"></script><script src=\"https://admin.down.swap.wang/assets/js/modern.min.js\"></script>";
    echo "<script src=\"https://admin.down.swap.wang/assets/plugins/datatables/js/jquery.dataTables.min.js\"></script>";
    echo "<script>var extable;\$(document).ready(function() {extable=\$('#example').DataTable({\"language\":{\"url\":\"https://cdn.datatables.net/plug-ins/e9421181788/i18n/Chinese.json\"}});});</script>";
    echo "</body></html>";
}



}
?>